package org.sems.sems.service.impl;

import org.sems.sems.entity.Aidhjlk;
import org.sems.sems.Mapper.AidhjlkMapper;
import org.sems.sems.service.AiHistoryService;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class AiHistoryServiceImpl implements AiHistoryService {

    // 注意：字段名与构造函数参数名保持一致
    private final AidhjlkMapper aidhjlkMapper;

    // 构造器注入
    public AiHistoryServiceImpl(AidhjlkMapper aidhjlkMapper) {
        this.aidhjlkMapper = aidhjlkMapper;
    }

    @Override
    public void saveAidhjlk(Aidhjlk record) {
        aidhjlkMapper.insert(record);
    }

    @Override
    public List<Aidhjlk> findRecentAidhjlkByUser(String username, int limit) {
        return aidhjlkMapper.selectRecentByUser(username, limit);
    }

    /***
     * 清空历史记录
     * @param twz
     * @param twzsfdm
     */
    @Override
    public Map<String, Object> clearHistory(String twz, int twzsfdm) {
        Map<String, Object> resultMap = new HashMap<>();
        try {
            //  添加工作经历数据
            if (aidhjlkMapper.clearHistory(twz, twzsfdm) > 0) {
                resultMap.put("code", 200);
                resultMap.put("msg", "success");
                resultMap.put("result", true);
            } else {
                resultMap.put("code", 500);
                resultMap.put("msg", "database error");
                resultMap.put("result", false);
            }
        } catch (Exception e) {
            e.printStackTrace();
            resultMap.put("code", 500);
            resultMap.put("msg", "server error");
            resultMap.put("result", false);
            resultMap.put("data", e.getMessage());
        }
        return resultMap;
    }
}
